/*
Date:20210611 22:40PM
key:计算深度的函数+判断深度差值的函数
 */
class Solution {
public:
    int deep(TreeNode* root)
    {
        if(root==NULL)
        {
            return 0;
        }
        else
        {
            return max(deep(root->left),deep(root->right))+1;
        }
    }
    bool isBalanced(TreeNode* root) 
    {
        if(root==NULL){return 1;}
        int ldeep=deep(root->left);
        int rdeep=deep(root->right);
        if(abs(ldeep-rdeep)<2)
        {
            return isBalanced(root->left)&&isBalanced(root->right); 
        }
        else{return 0;}
    }
};